<template>
  <div id="teamActivity">
    <router-view></router-view>
  </div>
</template>
<script>
import Vue from 'vue'
import { mapActions, mapGetters,mapMutations } from 'vuex'
import { getCookie } from '../../plugin/common'
import { jwtToken, banner } from '@/api/teamActivity/team'
import apiconfig from '@/api/apiConfig'
import { getClientIp } from '@/api/common'
export default {
  name: 'teamActivity',
  data() {
    return {
      // clientIp: mapState.state.clientIp,
    }
  },
  computed: {
    ...mapGetters(['isClientIp']),
    activityCode: function () {
      return this.$route.params.activityCode
    },
  },
  watch: {},
  methods: {
    ...mapMutations(['getClientIpState']),
    async ecptoken() {
      let vm = this
      getClientIp().then(res=>{
        vm.getClientIpState(res.Data)
         vm.jwtTokened(res.Data)
      })
      // await vm.getClientIPHTTP()
      // await vm.jwtTokened();
    },
    jwtTokened(clientIp) {
      let vm = this
      if (
        getCookie(apiconfig['enveriment']) ||
        window.location.href.indexOf('localhost') > -1
      ) {
        let obj = {}
        if (window.location.href.indexOf('localhost') > -1) {
          obj = {
            EcpToken: apiconfig['DEV_Token'],
            ClientIp: '124.193.98.144' || vm.isClientIp,
            AppId: apiconfig['appid'],
            // ClientId: Vue.$cookies.get("Ecp_ClientId")
            ClientId: '3220308055500668883',
          }
        } else {
          obj = {
            EcpToken: getCookie(apiconfig['enveriment']),
            ClientIp: clientIp||vm.isClientIp,
            AppId: apiconfig['appid'],
            ClientId: Vue.$cookies.get('Ecp_ClientId'),
          }
        }
        if (getCookie(apiconfig['enveriment'])) {
          jwtToken(obj).then((res) => {
            const now = Date.now()
            const { JwtToken, ExpireIn } = res.Content
            const tokenExpireTime = now + ExpireIn * 1000
            let obj = { JwtToken: JwtToken, ExpireIn: tokenExpireTime }
            window.localStorage.setItem('token', JSON.stringify(obj))
          })
        }
      }
    },
    getBanner() {
      let vm = this
      banner(vm.activityCode).then((res) => {
        console.log(res)
      })
    },
  },
  async created() {
    let vm = this

    if (getCookie(apiconfig['enveriment'])) {
      // await vm.ecptoken()
      // vm.getBanner()
    }
    if(JSON.parse(window.localStorage.getItem('token'))['JwtToken']){
        window.localStorage.removeItem('token')
    }
  // getClientIp().then(res=>{debugger
  //   mapState.state.clientIp=res.Data;
  // })
  },
  mounted() {},
}
</script>
<style scoped>
</style>